package com.assets.asset.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.assets.asset.annotation.TurnScrapType;
import com.assets.asset.domain.TScrap;
import com.assets.asset.service.ITAssetService;
import com.assets.asset.service.ITScrapService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.assets.common.annotation.Log;
import com.assets.common.core.controller.BaseController;
import com.assets.common.core.domain.AjaxResult;
import com.assets.common.enums.BusinessType;
import com.assets.common.utils.poi.ExcelUtil;
import com.assets.common.core.page.TableDataInfo;

/**
 * 报废列表Controller
 *
 * @author bin
 * @date 2023-03-13
 */
@RestController
@RequestMapping("/asset/scrap")
public class TScrapController extends BaseController
{
    @Autowired
    private ITScrapService tScrapService;

    @Autowired
    private ITAssetService tAssetService;

    /**
     * 查询报废列表列表
     */
    @PreAuthorize("@ss.hasPermi('asset:scrap:list')")
    @GetMapping("/list")
    public TableDataInfo list(TScrap tScrap)
    {
        startPage();
        List<TScrap> list = tScrapService.selectTScrapList(tScrap);
        return getDataTable(list);
    }

    /**
     * 导出报废列表列表
     */
    @PreAuthorize("@ss.hasPermi('asset:scrap:export')")
    @Log(title = "报废列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TScrap tScrap)
    {
        List<TScrap> list = tScrapService.selectTScrapList(tScrap);
        ExcelUtil<TScrap> util = new ExcelUtil<TScrap>(TScrap.class);
        util.exportExcel(response, list, "报废列表数据");
    }

    /**
     * 获取报废列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('asset:scrap:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        AjaxResult ajax = AjaxResult.success(tScrapService.selectTScrapById(id));
        ajax.put("assetAdmins",tAssetService.selectAdminList());
        return ajax;
    }

    /**
     * 新增报废列表
     */
    @PreAuthorize("@ss.hasPermi('asset:scrap:add')")
    @Log(title = "报废列表", businessType = BusinessType.INSERT)
    @PostMapping
    @TurnScrapType
    public AjaxResult add(@RequestBody TScrap tScrap)
    {
        return toAjax(tScrapService.insertTScrap(tScrap));
    }

    /**
     * 修改报废列表
     */
    @PreAuthorize("@ss.hasPermi('asset:scrap:edit')")
    @Log(title = "报废列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TScrap tScrap)
    {
        return toAjax(tScrapService.updateTScrap(tScrap));
    }

    /**
     * 删除报废列表
     */
    @PreAuthorize("@ss.hasPermi('asset:scrap:remove')")
    @Log(title = "报废列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tScrapService.deleteTScrapByIds(ids));
    }
}
